package com.LeetCode.BackTrace;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * 电话号码字母组合
 */
public class PhoneNumberSet {
    String[] lettersMap = {
            "",
            "",
            "abc",
            "def",
            "ghi",
            "jkl",
            "mno",
            "pqrs",
            "tuv",
            "wxyz"
    };

    List<String> res = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        if(digits.equals(""))
            return res;
        backtrace(digits, 0, "");
        return res;
    }

    public void backtrace(String digits, int index, String s){
        if(index == digits.length()){
            res.add(s);
            return;
        }

        String letter = lettersMap[digits.charAt(index) - '0'];
        for(int i = 0; i<letter.length(); i++){
            backtrace(digits, index + 1, s + letter.charAt(i));
        }
    }

    @Test
    public void test(){
        letterCombinations("23").forEach(System.out::println);
    }
}
